package com.example.sevicedemo;

import android.content.Intent;
import android.service.notification.NotificationListenerService;
import android.service.notification.StatusBarNotification;

/**
 * @author ypk
 * 创建日期：2021/12/27  17:32
 * 描述：https://www.jianshu.com/p/981e7de2c7be?from=jiantop.com
 */
public class WeChatNotificationListenerService extends NotificationListenerService {
    private static final String TAG = "WeCNLService";

    @Override
    public void onCreate() {
        System.out.println(TAG + ".onCreate");
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        System.out.println(TAG + ".onStartCommand");
        return super.onStartCommand(intent, flags, startId);
    }

    /**
     * 当有新通知到来时会回调
     */
    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        super.onNotificationPosted(sbn);
        System.out.println(TAG + ".onNotificationPosted");
    }

    /**
     * 当有通知移除时会回调
     */
    @Override
    public void onNotificationRemoved(StatusBarNotification sbn) {
        super.onNotificationRemoved(sbn);
        System.out.println(TAG + ".onNotificationRemoved");
    }

    /**
     * 在侦听器连接上
     */
    @Override
    public void onListenerConnected() {
        super.onListenerConnected();
        System.out.println(TAG + ".onListenerConnected");
    }

    /**
     * 在侦听器断开连接时
     */
    @Override
    public void onListenerDisconnected() {
        super.onListenerDisconnected();
        System.out.println(TAG + ".onListenerDisconnected");
    }
}
